package com.yuhanginfo.modules.web.web;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yuhanginfo.common.utils.StringUtils;
import com.yuhanginfo.common.web.BaseController;
import com.yuhanginfo.modules.web.entity.WebYongUser;
import com.yuhanginfo.modules.web.service.WebSmsService;
import com.yuhanginfo.modules.web.service.WebYongUserService;

/**
 * 验证码
 * @author yinhao
 * @version 2017-11-6
 */
@Controller
@RequestMapping(value = "${frontPath}/sms")
public class WebSmsController extends BaseController {

	@Autowired
	private WebYongUserService webYongUserService;
	
	@Autowired
	private WebSmsService webSmsService;
	
	@ModelAttribute
	public WebYongUser get(@RequestParam(required=false) String id) {
		WebYongUser entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = webYongUserService.get(id);
		}
		if (entity == null){
			entity = new WebYongUser();
		}
		return entity;
	}

	@RequestMapping(value = "getCode" , method = RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> getCode(String mobile) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
		webSmsService.getÇode(mobile);
		return resultMap;
	}
	
	@RequestMapping(value = "checkCode" , method = RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> checkÇode(String mobile,String code) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
		resultMap.putAll(webSmsService.checkÇode(mobile,code));
		return resultMap;
	}

	@RequestMapping(value = "checkCode2" , method = RequestMethod.POST)
	@ResponseBody
	public boolean checkÇode2(String mobile,String code) {
		return webSmsService.checkÇode2(mobile,code);
	}
	
}